package kr.cadis.clms.dao;

import java.io.Reader;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import kr.cadis.clms.model.LimitCash;
import kr.cadis.clms.model.LimitCash;
import kr.cadis.clms.model.Person;

public class LimitCashDao {
	Reader reader;
	SqlMapClient sqlMap;
	
	public LimitCashDao() {
		try {
			reader = Resources.getResourceAsReader("SqlMapConfig.xml");
			sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
		}
		catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}
	
	public boolean insert(LimitCash limitCash) throws SQLException {
		sqlMap.insert("LimitCash.insert", limitCash);
		
		if(limitCash.getNo() == 0) { 
			return false;
		} else {
			return true;
		}	
	}
	
	public boolean delete(int no) throws SQLException {
		if(sqlMap.delete("LimitCash.delete", no) == 1) { 
			return true;
		} else {
			return false;
		}	
	}
	
	public boolean update(LimitCash limitCash) throws SQLException {
		sqlMap.update("LimitCash.update", limitCash);
		
		if(limitCash.getNo() == 0) { 
			return false;
		} else {
			return true;
		}	
	}
	
	public LimitCash selectByNo(int no) throws SQLException {
		LimitCash limitCash = (LimitCash) sqlMap.queryForObject("LimitCash.selectByNo", no);
		
		return limitCash;
	}
	
	public List<LimitCash> selectAll() throws SQLException {
		List<LimitCash> limitCashes = sqlMap.queryForList("LimitCash.selectAll");
		
		return limitCashes;
	}
	
	public int selectMoneyForTheDate(String strTheDate) throws SQLException {		
		int money = (Integer) sqlMap.queryForObject("LimitCash.selectMoneyForTheDate", strTheDate);
		
		return money;
	}
	
}
